import jwt
import datetime
from django.conf import settings
class JWTTool:
    def getToken(self,userid,account):
        data={
            'userid':userid,
            'account':account,
            'exp':datetime.datetime.now()+datetime.timedelta(hours=1)
        }
        return "Bearer "+jwt.encode(payload=data,key=settings.SECRET_KEY,algorithm='HS256')
    def checkToken(self,token):
        return jwt.decode(token,key=settings.SECRET_KEY,algorithms='HS256')


tool=JWTTool()
# print(tool.getToken(1,'admin'))
# print(tool.checkToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjEsImFjY291bnQiOiJhZG1pbiIsImV4cCI6MTczNDk1NTgwMH0.tHwQ4LimSG1FuUMhHJ3aMvcSRIZ8EJoS-PMjdA9M6eg'))